home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / faq-s.zip / DOORS.PAS < prev    next >
Pascal/Delphi Source File  |  1991-04-13  |  13KB  |  438 lines

  1. {$R-,S-,I-,D-,F+,V-,B-,N-,L+,O+ }
  2. {$M 65500,0,0 }
  3.  
  4. unit doors;
  5.  
  6. interface
  7.  
  8. uses crt,gentypes,modem,configrt,gensubs,subs1,subs2,userret,statret,
  9.      textret,mainr1,mainr2;
  10.  
  11. procedure doorsmenu;
  12.  
  13. implementation
  14.  
  15. procedure doorsmenu;
  16.  
  17.   function numdoors:integer;
  18.   begin
  19.     numdoors:=filesize (dofile)
  20.   end;
  21.  
  22.   procedure seekdofile (n:integer);
  23.   begin
  24.     seek (dofile,n-1)
  25.   end;
  26.  
  27.   procedure opendofile;
  28.   var arkanoid:integer;
  29.   begin
  30.     assign (dofile,bbsdatadir+'Doors.dat');
  31.     reset (dofile);
  32.     if ioresult<>0 then begin
  33.       close (dofile);
  34.       arkanoid:=ioresult;
  35.       rewrite (dofile)
  36.     end
  37.   end;
  38.  
  39.   procedure maybemakebatch (fn:lstr);
  40.   var tf:text;
  41.       vallco:boolean;
  42.   begin
  43.     if not issysop then exit;
  44.     writestr ('Make new batch file '+fn+'? *');
  45.     if not yes then exit;
  46.     assign (tf,fn);
  47.     rewrite (tf);
  48.     if ioresult<>0 then begin
  49.       writeln (^M'Couldn''t create file!');
  50.       exit
  51.     end;
  52.     writeln (^M'Enter Text, blank line to end.'^M);
  53.     repeat
  54.       writestr ('─> &');
  55.       vallco:=length(input)=0;
  56.       if not vallco then writeln (tf,input)
  57.     until vallco;
  58.     textclose (tf);
  59.     writeln (^M'Batch file created!');
  60.     writelog (10,4,fn)
  61.   end;
  62.  
  63.   procedure getdoorinfo (var d:doorrec);
  64.   var m:message;
  65.   begin
  66.     writeln (^B^M'Enter Info about this Door:'^M);
  67.     delay (1000);
  68.     titlestr:='Door Information';
  69.     d.info:=editor (m,false,'Door Information')
  70.   end;
  71.  
  72.   function checkbatchname (var qq):boolean;
  73.   var i:lstr absolute qq;
  74.       batman:integer;
  75.   begin
  76.     batman:=pos('.',i);
  77.     if batman<>0 then i[0]:=chr(batman-1);
  78.     i:=i+'.BAT';
  79.     checkbatchname:=validfname(i)
  80.   end;
  81.  
  82.   procedure maybemakedoor;
  83.   var shy:integer;
  84.       d:doorrec;
  85.   begin
  86.     if not issysop then exit;
  87.     shy:=numdoors+1;
  88.     writestr ('Make new Door #'+strr(shy)+'? *');
  89.     if not yes then exit;
  90.     writestr (^M'Name:');
  91.     if length(input)<1 then exit;
  92.     d.name:=input;
  93.     writestr ('Access Level:');
  94.     if length(input)<1 then exit;
  95.     d.level:=valu(input);
  96.     writestr ('Name/Path of batch file:');
  97.     if length(input)<1 then exit;
  98.     if not checkbatchname(input) then begin
  99.       writeln ('Invalid filename: '^S,input);
  100.       exit
  101.     end;
  102.     d.batchname:=doordir+input;
  103.     getdoorinfo (d);
  104.     if d.info<0 then exit;
  105.     d.numused:=0;
  106.     seekdofile (shy);
  107.     write (dofile,d);
  108.     if not exist (d.batchname) then begin
  109.       writeln (^B'ERROR: Can''t open Batch file ',d.batchname);
  110.       maybemakebatch (d.batchname)
  111.     end;
  112.     writeln (^B^M'Door created!');
  113.     writelog (10,3,d.name)
  114.   end;
  115.  
  116.   function haveaccess (n:integer):boolean;
  117.   var d:doorrec;
  118.   begin
  119.     haveaccess:=false;
  120.     seekdofile (n);
  121.     read (dofile,d);
  122.     if ulvl>=d.level
  123.       then haveaccess:=true
  124.       else writeln ('That Door is locked.')
  125.   end;
  126.  
  127.   procedure listdoors;
  128.   var d:doorrec;
  129.       cnt:integer;
  130.   begin
  131.     if exist (textfiledir+'DoorList.BBS') then begin
  132.      printfile (textfiledir+'DoorList.BBS');
  133.       exit
  134.      end;
  135.     if not (asciigraphics in urec.config) then begin
  136.     writehdr ('Available Doors');
  137.     seekdofile (1);
  138.     writeln (^M^R'## Online Door Name            Level Times used');
  139.     for cnt:=1 to numdoors do begin
  140.       read (dofile,d);
  141.       if ulvl>=d.level then begin
  142.         tab (strr(cnt)+'.',3);
  143.         tab (d.name,27);
  144.         writeln (d.level:3,d.numused:5);
  145.         if break then exit
  146.       end
  147.     end;
  148.     end else begin
  149.     seekdofile (1);
  150.     writeln (^M^R'┌──┬──────────────────────────────┬─────┬──────────┐');
  151.     writeln (^R'│##│Online Door Name              │Level│Times Used│');
  152.     writeln (^R'├──┼──────────────────────────────┼─────┼──────────┤');
  153.     for cnt:=1 to numdoors do begin
  154.        read (dofile,d);
  155.        if ulvl>=d.level then begin
  156.          tab (^R'│'^S+strr(cnt),5);
  157.          tab (^R'│'^S+d.name,33);
  158.          tab (^R'│'^S+strr(d.level),8);
  159.          tab (^R'│ '^S+strr(d.numused),13);
  160.          writeln (^R'│');
  161.       if break then exit
  162.     end
  163.     end
  164.    end;
  165.   if (asciigraphics in urec.config) then
  166.     writeln (^R'└──┴──────────────────────────────┴─────┴──────────┘')
  167.   end;
  168.  
  169.   function getdoornum (txt:mstr):integer;
  170.   var g:boolean;
  171.       n:integer;
  172.   begin
  173.     getdoornum:=0;
  174.     g:=false;
  175.     repeat
  176.       writestr (^R'Door Number to '^P+txt+^R' ['^S'?/List'^R']:');
  177.       if input='?' then listdoors else g:=true
  178.     until g;
  179.     if length(input)=0 then exit;
  180.     n:=valu(input);
  181.     if (n<1) or (n>numdoors)
  182.       then writeln ('Door number out of range!')
  183.       else if haveaccess(n)
  184.         then getdoornum:=n
  185.   end;
  186.  
  187.   procedure opendoor;
  188.   var n,bd,p:integer;
  189.       d:doorrec;
  190.       batchf,outf:text;
  191.       q:boolean;
  192.       tmp,params:lstr;
  193.   begin
  194.     n:=getdoornum ('open');
  195.     if n=0 then exit;
  196.     seekdofile (n);
  197.     read (dofile,d);
  198.     printtext (d.info);
  199.     nobreak:=true;
  200.     writestr (^B^M^P'Press ['^S'Space'^P'] to Open the Door, or ['^S'X'^P'] to Abort');
  201.     if upcase(waitforchar)='X' then exit;
  202.     writeln (^R'Opening door: '^S,d.name);
  203.     q:=true;
  204.     repeat
  205.       assign (batchf,d.batchname);
  206.       reset (batchf);
  207.       if ioresult<>0 then begin
  208.         q:=false;
  209.         close (batchf);
  210.         iocode:=ioresult;
  211.         if not issysop then begin
  212.           fileerror ('Opendoor',d.batchname);
  213.          exit
  214.         end else begin
  215.           maybemakebatch (d.batchname);
  216.          if not exist (d.batchname) then exit
  217.         end
  218.       end
  219.     until q;
  220.     assign (outf,'DOOR.BAT');
  221.     rewrite (outf);
  222.     writeln (outf,'TEMPDOOR ',params);
  223.     textclose (outf);
  224.     assign (outf,'TEMPDOOR.BAT');
  225.     rewrite (outf);
  226.     while not eof(batchf) do begin
  227.       readln (batchf,tmp);
  228.       writeln (outf,tmp)
  229.     end;
  230.     if online then bd:=baudrate else bd:=0;
  231.     getdir (0,tmp);
  232.     writeln (outf,'cd '+tmp);
  233.     writeln (outf,'main.bat ',unum,' ',bd,' ',ord(parity),' D');
  234.     textclose (batchf);
  235.     textclose (outf);
  236.     d.numused:=d.numused+1;
  237.     seekdofile (n);
  238.     write (dofile,d);
  239.     writelog (9,1,d.name);
  240.     updateuserstats (false);
  241.     writeurec;
  242.     writestatus;
  243.     ensureclosed;
  244.     halt (e_door)
  245.   end;
  246.  
  247.   procedure getinfo;
  248.   var n:integer;
  249.       d:doorrec;
  250.   begin
  251.     n:=getdoornum ('get information on');
  252.     if n=0 then exit;
  253.     seekdofile (n);
  254.     read (dofile,d);
  255.     writeln;
  256.     printtext (d.info)
  257.   end;
  258.  
  259.   procedure changedoor;
  260.   var n:integer;
  261.       d:doorrec;
  262.   begin
  263.     n:=getdoornum ('Change');
  264.     if n=0 then exit;
  265.     seekdofile (n);
  266.     read (dofile,d);
  267.     writeln ('Name: ',d.name);
  268.     writestr ('New name:');
  269.     if length(input)>0 then d.name:=input;
  270.     writeln (^M'Level: ',d.level);
  271.     writestr ('New level:');
  272.     if length(input)>0 then d.level:=valu(input);
  273.     writeln (^M'Batch file name: ',d.batchname);
  274.     writestr ('New batch file name:');
  275.     if length(input)>0 then
  276.      if checkbatchname (input)
  277.       then d.batchname:=input
  278.      else writeln ('Invalid filename: '^S,input);
  279.     maybemakebatch (d.batchname);
  280.     writeln;
  281.     printtext (d.info);
  282.     writestr (^M^R'Replace text ['^S'y/n'^R']:');
  283.     if yes then repeat
  284.      deletetext (d.info);
  285.      getdoorinfo (d);
  286.      if d.info<0 then writeln (^M'You must enter some information.')
  287.     until d.info>=0;
  288.     seekdofile (n);
  289.     write (dofile,d);
  290.     writelog (10,1,d.name)
  291.   end;
  292.  
  293.   procedure deletedoor;
  294.   var n,cnt:integer;
  295.       td,d:doorrec;
  296.       f:file;
  297.   begin
  298.     n:=getdoornum ('Delete');
  299.     if n=0 then exit;
  300.     seekdofile (n);
  301.     read (dofile,d);
  302.     writestr ('Delete '+d.name+' [y/n]:');
  303.     if not yes then exit;
  304.     writeln ('Deleting...');
  305.     seekdofile (n+1);
  306.     for cnt:=n to filesize(dofile)-1 do begin
  307.       read (dofile,td);
  308.       seekdofile (cnt);
  309.       write (dofile,td)
  310.     end;
  311.     seek (dofile,filesize(dofile)-1);
  312.     truncate (dofile);
  313.     deletetext (d.info);
  314.     writestr (^M'Erase disk file '+d.batchname+'? *');
  315.      if yes then begin
  316.       assign (f,d.batchname);
  317.       erase (f);
  318.       if ioresult<>0 then writeln ('(File not found)')
  319.     end;
  320.     writelog (10,2,d.name)
  321.   end;
  322.  
  323.   procedure sysopdoors;
  324.   var zebra:integer;
  325.   begin
  326.     if (not remotedoors) and carrier then begin
  327.       writestr ('Sorry, remote door maintenance is not allowed!');
  328.       writestr ('(Re-configure to change this setting)');
  329.       exit
  330.     end;
  331.     repeat
  332.       zebra:=menu('Doors Sysop','SDOORS','QCAD?');
  333.       case zebra of
  334.         2:changedoor;
  335.         3:maybemakedoor;
  336.         4:deletedoor;
  337.         5:begin
  338. writeln ('C╔═════════════════════════════════════╗Hs');
  339. writeln ('uC║ Doors Sysop Section                 ║Hs');
  340. writeln ('uC╚═════════════════════════════════════╝HHC╔════s');
  341. writeln ('u═════════════════════════════════╗HC║ [As');
  342. writeln ('uAdd Door                        ║HC║ [Cs');
  343. writeln ('uChange Door                     ║HC║ [s');
  344. writeln ('uDDelete Door                     ║Hs');
  345. writeln ('uC║ [QQuit                            s');
  346. writeln ('u║HC║ [?View This Menu           s');
  347. writeln ('u       ║HC╚═════════════════════════════════════╝');
  348. writeln;
  349. pause;
  350.            end;
  351.       end
  352.     until hungupon or (zebra=1) or (filesize(dofile)=0)
  353.   end;
  354.  
  355. var x1,x2,x3,space,harrier,zebra:integer;
  356.     y1,y2,y3:real;
  357. begin
  358.   writeln ('On-Line Doors');
  359.   if not allowdoors then begin
  360.     writestr ('All doors are locked.');
  361.     if issysop then writestr ('[Re-configure to change this setting]');
  362.     exit
  363.   end;
  364.   if fromdoor then begin
  365.     fromdoor:=false;
  366.     if returnto='D' then writestr (^M^M'Welcome back to FAQ!');
  367.     settimeleft (urec.timetoday)
  368.   end;
  369.   x1:=urec.nbu;
  370.   x2:=urec.numon;
  371.   if x1<1 then x1:=1;
  372.   if x2<1 then x2:=1;
  373.   y1:=int(x1);
  374.   y2:=int(x2);
  375.   y1:=y1;
  376.   y2:=y2;
  377.   y3:=y1/y2;
  378.   y3:=y3*100;
  379.   x3:=trunc(y3);
  380.   write (^R'Required Post/Call Ratio: ['^S);
  381.   for space:=1 to 3-(length(strr(doorpcr))) do write (' ');
  382.   write (strr(doorpcr));
  383.   writeln ('%'^R']');
  384.   write (^R'Your Post/Call Ratio:     ['^S);
  385.   for harrier:=1 to 3-(length(strr(x3))) do write (' ');
  386.   write (strr(x3));
  387.   writeln ('%'^R']');
  388.   write (^M^R'PCR Status: ['^S);
  389.   if ulvl>=pcrexempt then write ('Exempt from PCR.') else
  390.   if (x3<doorpcr) and (ulvl<pcrexempt) then write ('PCR too low!') else
  391.   if (x3>=doorpcr) and (ulvl<pcrexempt) then write ('Passed PCR check.');
  392.   writeln (^R']'^M);
  393.   if (x3<doorpcr) and (ulvl<pcrexempt) then begin
  394.    writeln (^B^R'Your Posts-per-Call Ratio is too low!');
  395.    writeln ('Go post a message or two.');
  396.    exit;
  397.   end;
  398.   cursection:=doorssysop;
  399.   opendofile;
  400.   if numdoors=0 then begin
  401.     writestr ('No doors exist!');
  402.     maybemakedoor;
  403.     if numdoors=0 then begin
  404.       close (dofile);
  405.       exit
  406.     end
  407.   end;
  408.   writehdr ('Doors');
  409.   repeat
  410.     zebra:=menu('Doors','DOORS','QLOI%?');
  411.     case zebra of
  412.       2:listdoors;
  413.       3:opendoor;
  414.       4:getinfo;
  415.       5:sysopdoors;
  416.       6:begin
  417. writeln ('C╔═════════════════════════════════════╗Hs');
  418. writeln ('uC║ Doors Section                       ║Hs');
  419. writeln ('uC╚═════════════════════════════════════╝HHC╔════s');
  420. writeln ('u═════════════════════════════════╗HC║ [I]  s');
  421. writeln ('uGet Info on Door               ║HC║ [Ls');
  422. writeln ('u]  List Doors                     ║HC║ [s');
  423. writeln ('uO]  Open (Run) Door                ║Hs');
  424. writeln ('uC║ [Q]  Quit                           s');
  425. writeln ('u║HC║ [%]  Doors Sysop Section     s');
  426. writeln ('u       ║HC║ [?]  View This Menu   s');
  427. writeln ('u              ║HC╚═══════════════════════════════A');
  428. writeln ('C══════╝');
  429. writeln;
  430. pause;
  431.            end;
  432.     end
  433.   until hungupon or (zebra=1) or (filesize(dofile)=0);
  434.   close (dofile)
  435. end;
  436.  
  437. begin
  438. end.